package com.jt.blog.thread;



import java.util.ArrayList;
import java.util.List;

public class ListTests {
    static List<Integer> cache = new ArrayList<>();
    static  List<Integer> selectData() {
        if (cache.isEmpty()) {
            synchronized (cache) {
                if (cache.isEmpty()) {
                    cache.add(100);
                }
            }
        }
            return cache;

    }

    public static void main(String[] args) {
//        List<Integer> data = selectData();

        Thread t1 = new Thread(( )->{
            System.out.println(selectData());
        });
        Thread t2 = new Thread(( )->{
            System.out.println(selectData());
        });
        Thread t3 = new Thread(( )->{
            System.out.println(selectData());
        });
        t1.start();
        t2.start();
        t3.start();
    }

}
